<?php
namespace Application\Controller;

use Application\Model\Dao\UpdateDao;
use Application\Service\XmlService;
use Zend\Authentication\AuthenticationService;
use Zend\View\Model\ViewModel;
use Zend\View\Model\JsonModel;
use Application\Service\ImageService;
use Application\Service\UpdateService;

class FileController extends LoginAwareController
{
    public function downloadAction(){

        $request = $this->getRequest();
        $imageId = $request->getQuery('id');
        $fileDao = $this->getServiceLocator()->get('file');
        $imageContent = $fileDao->getProfileImage($imageId);
        $response = $this->getResponse();
        $response->setContent($imageContent['data']);
        $response->getHeaders()
            ->addHeaderLine('Content-Transfer-Encoding', 'binary')
            ->addHeaderLine('Content-Type', 'application/octet-stream')
            ->addHeaderLine('Content-Disposition', ' attachment;filename='.$imageContent['title'])
            ->addHeaderLine('Content-Length', mb_strlen($imageContent['data']));
        return $response;

    }
}

?>